package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoods;
import com.qf.pojo.DtsGoodsAttribute;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {

    @Autowired
    DtsGoodsProductMapper goodsProductMapper;

    @Override
    public Integer findTotal() {

        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(DtsGoodsProduct::getDeleted, false);

        Integer count = goodsProductMapper.selectCount(wrapper);

        return count;
    }

    @Override
    public List<DtsGoodsProduct> findGoodsProduct(Integer id) {

        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getDeleted, false);
        wrapper.eq(DtsGoodsProduct::getGoodsId, id);

        return goodsProductMapper.selectList(wrapper);
    }

    @Override
    public void deleteByGid(Integer id) {

        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId, id);

        goodsProductMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsProduct product) {

        product.setDeleted(false);
        product.setAddTime(new Date());
        product.setUpdateTime(new Date());

        goodsProductMapper.insert(product);
    }
}
